---
title:  Runtime parameters for custom models
description: Add runtime parameters to a custom model through the model metadata.
section_name: MLOps
maturity: public-preview
---

# Runtime parameters for custom models

!!! info "Availability information"
    Runtime parameters for custom models are off by default. Contact your DataRobot representative or administrator for information on enabling this feature.

    <b>Feature flag:</b> Enable the Injection of Runtime Parameters for Custom Models

Now available as a public preview feature, you can add runtime parameters to a custom model through the model metadata, making your custom model code easier to reuse.

## Define runtime parameters

To define runtime parameters, you can add the following `runtimeParameterDefinitions` in `model-metadata.yaml`:

Key            | Value
---------------|------
`fieldName`    | The name of the runtime parameter.
`type`         | The data type the runtime parameter contains:`string` or `credential`.
`defaultValue` | (Optional) The default string value for the runtime parameter (the credential type doesn't support default values).
`description`  | (Optional) A description of the purpose or contents of the runtime parameter.

!!! note
    If you define a runtime parameter without specifying a `defaultValue`,  the default value is `None`.

``` yaml title="Example: model-metadata.yaml"

name: runtime-parameter-example
type: inference
targetType: regression

runtimeParameterDefinitions:
- fieldName: my_first_runtime_parameter
  type: string
  description: My first runtime parameter.

- fieldName: runtime_parameter_with_default_value
  type: string
  defaultValue: Default
  description: A runtime parameter with a default value.

- fieldName: runtime_parameter_for_credentials
  type: credential
  description: A runtime parameter containing a dictionary of credentials.

```

The `credential` runtime parameter type supports any `credentialType` value available in the DataRobot REST API. The credential information included depends on the `credentialType`, as shown in the examples below:

!!! note
    For more information on the supported credential types, see the [API reference documentation for credentials](https://docs.datarobot.com/en/docs/api/reference/public-api/credentials.html#schemacredentialsbody).

<table>
  <thead>
    <tr>
      <th>Credential Type</th>
      <th>Example</th>
    </tr>
  </thead>             
  <tbody>
    <tr>         
      <td><code>basic</code></td>
      <td>
        <pre>
basic:
  credentialType: basic
  description: string
  name: string
  password: string
  user: string
        </pre>
      </td>
    </tr>
    <tr>                
      <td><code>azure</code></td>
      <td>
        <pre>
azure:
  credentialType: azure
  description: string
  name: string
  azureConnectionString: string
        </pre>
      </td>
    </tr>
    <tr>                          
      <td><code>gcp</code></td>
      <td>
        <pre>
gcp:
  credentialType: gcp
  description: string
  name: string
  gcpKey: string
        </pre>
      </td>
    </tr>
    <tr>                            
      <td><code>s3</code></td>
      <td>
        <pre>
s3:
  credentialType: s3
  description: string
  name: string
  awsAccessKeyId: string
  awsSecretAccessKey: string
  awsSessionToken: string
        </pre>
      </td>
    </tr>
    <tr>                            
      <td><code>api_token</code></td>
      <td>
        <pre>
api_token:
  credentialType: api_token
  apiToken: string
  name: string
        </pre>
      </td>
    </tr>
  </tbody>
</table>

## Provide override values during local development

For local development with DRUM, you can specify a `.yaml` file containing the values of the runtime parameters. The values defined here override the `defaultValue` set in `model-metadata.yaml`:

``` yaml title="Example: .runtime-parameters.yaml"

my_first_runtime_parameter: Hello, world.
runtime_parameter_with_default_value: Override the default value.
runtime_parameter_for_credentials:
  credentialType: basic
  name: credentials
  password: password1
  user: user1


```

When using DRUM, the new `--runtime-params-file` option specifies the file containing the runtime parameter values:

``` sh title="Example: --runtime-params-file"

drum score --runtime-params-file .runtime-parameters.yaml --code-dir model_templates/python3_sklearn --target-type regression --input tests/testdata/juniors_3_year_stats_regression.csv

```

## Import and use runtime parameters in custom code

To import and access runtime parameters, you can import the `RuntimeParameters` module in your code in `custom.py`:

``` py title="Example: custom.py"

from datarobot_drum import RuntimeParameters


def mask(value, visible=3):
    return value[:visible] + ("*" * len(value[visible:]))


def transform(data, model):
    print("Loading the following Runtime Parameters:")
    parameter1 = RuntimeParameters.get("my_first_runtime_parameter")
    parameter2 = RuntimeParameters.get("runtime_parameter_with_default_value")
    print(f"\tParameter 1: {parameter1}")
    print(f"\tParameter 2: {parameter2}")

    credentials = RuntimeParameters.get("runtime_parameter_for_credentials")
    if credentials is not None:
        credential_type = credentials.pop("credentialType")
        print(
            f"\tCredentials (type={credential_type}): "
            + str({k: mask(v) for k, v in credentials.items()})
        )
    else:
        print("No credential data set")
    return data


```

## View and edit runtime parameters in DataRobot

When you add a `model-metadata.yaml` file with `runtimeParameterDefinitions` to DataRobot while [creating a custom model](custom-inf-model), the **Runtime Parameters** section appears on the **Assemble** tab for that custom model. After you build the environment and create a new version, you can click **View and Edit** to configure the parameters:

![](images/assemble-tab-runtime-params.png)

!!! note
    Each change to a runtime parameter creates a new minor version of the custom model.

After you [test a model](custom-model-test) with runtime parameters in the **Custom Model Workshop**, you can navigate to the **Test > Runtime Parameters** to view the model's parameters:

![](images/test-tab-runtime-params.png)
